package com.example.application.weather;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.widget.GridView;
import android.widget.ProgressBar;
import android.widget.SimpleAdapter;

import com.example.application.R;
import com.example.application.task.WeatherTask3;

import java.util.HashMap;
import java.util.List;

public class WeatherListActivity extends AppCompatActivity {
    Handler handler;
    String TAG="WeatherListActivity";
    private ProgressBar bar;
    SimpleAdapter listItemAdapter;
    List<HashMap<String, String>> list;
    //GridView gridView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_ins_list);
            GridView mylist = findViewById(R.id.mylistview);
            bar=findViewById(R.id.progressBar);
            mylist.setEmptyView(bar);
            handler = new Handler(Looper.myLooper()) {
                @Override
                public void handleMessage(@NonNull Message msg) {
                    if (msg.what == 5) {
                        list = (List<HashMap<String, String>>) msg.obj;
                        //String[] list_data={};
                        listItemAdapter = new SimpleAdapter(WeatherListActivity.this, list,
                                R.layout.list_item,
                                new String[]{"city","temp","wind"},
                                new int[]{R.id.title1, R.id.title2,R.id.title3});
                        mylist.setAdapter(listItemAdapter);
                    }
                    if (msg.what == 5) {
                        list = (List<HashMap<String, String>>) msg.obj;
                    }
                    super.handleMessage(msg);
                }
            };
            WeatherTask3 mytask=new WeatherTask3();
            mytask.setHandler(handler);
            Thread t = new Thread(mytask);
            t.start();
        }
    }
